<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 1 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../plugins/echarts/echarts.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析<small>套餐占比</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>套餐占比</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!-- 2 为 ECharts 准备一个具备大小（宽高）的 DOM  id="chart1" style="height:600px;"-->
            <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
            <div id="chart1" style="/*width: 600px;*/height:600px;"></div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/echarts/echarts.js"></script>


<script type="text/javascript">

    // 3 基于准备好的dom，初始化echarts实例
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('chart1'));
    var option = {
        //左边导航
        legend: {
            orient: "vertical",
            left: "left",
            data: []
        },
        //鼠标移动上去显示内容
        tooltip: {
            trigger: 'item'
        },
        series: [
            {
                type: 'pie',
                data: [],

                /*显示百分比*/
                label: {
                    normal: {
                        formatter: '{b}:{c}: ({d}%)',
                        textStyle: {
                            fontWeight: 'normal',
                            fontSize: 15
                        }
                    }
                },
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }

            }
        ]
    };

    /*异步请求*/
    axios.get("/report/getSetmealReport").then((rs) => {
        /*console.log(rs.data.data.setmealNames);
        console.log(rs.data.data.setmealCount);*/
        let setData = [];
        for (let i = 0; i < rs.data.data.setmealNames.length; i++) {
            let setmeal = {};
            setmeal.name = rs.data.data.setmealNames[i];
            setmeal.value = rs.data.data.setmealCount[i];
            setData.push(setmeal);
        }
        console.log(setData)
        /*设置echats配置与数据*/
        myChart.setOption({
            legend: {
                orient: "vertical",
                left: "left",
                data: setData
            },
            series: [
                {
                    type: 'pie',
                    data: setData
                }
            ]
        })
    })

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    // 4 发送ajax请求,获取结果, 使用刚指定的配置项和数据显示图表。


</script>
</html>


<!--// 指定图表的配置项和数据-->
<!--// var option = {-->
<!--//     title: {-->
<!--//         text: 'ECharts 入门示例'-->
<!--//     },-->
<!--//     tooltip: {},-->
<!--//     legend: {-->
<!--//         data:['销量']-->
<!--//     },-->
<!--//     // xAxis: {-->
<!--//     //     data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]-->
<!--//     // },-->
<!--//     // yAxis: {},-->
<!--//     series: [{-->
<!--//         // name: '销量',-->
<!--//         type: 'pie',-->
<!--//         data: [5, 20, 36, 10, 10, 20]-->
<!--//     }]-->
<!--// };-->